package org.db2.project.airline.dao.impl;

import org.db2.project.airline.dao.BookingStatusDAO;
import org.db2.project.airline.dao.DAOException;
import org.db2.project.airline.model.BookingStatus;
import org.hibernate.HibernateException;

/**
 *
 */
public class HibernateBookingStatusDAO extends HibernateGenericDAO<BookingStatus> implements BookingStatusDAO {

    public HibernateBookingStatusDAO() {
        // empty constructor
    }

    @Override
    public BookingStatus findByStatusName(String statusName) throws DAOException {

        try {
            return (BookingStatus) getSession()
                    .createQuery("from BookingStatus st where st.status = :statusName")
                    .setParameter("statusName", statusName)
                    .uniqueResult();
        } catch (HibernateException e) {
            throw new DAOException("Error occurred when retrieving entity from persistence.", e);
        }
    }
}
